<?php
// 本类由系统自动生成，仅供测试用途
class LoginAction extends Action {
    public function check(){
    	$user=M('User');
    	$username=$_POST['username'];

    	$password=$_POST['password'];

             if(strlen($password)==32){
                        $password=$_POST['password'];
             }
             if(strlen($password)!=32){
                        $password=md5($_POST['password']);
             }
             $remember=$_POST['remember'];
    	$row=$user->where("username='{$username}' and password='{$password}'")->find();
    	if($row){
                        //登陆成功就把用户名，头像保存到$_SESSION里面，供页面使用
    	                  $_SESSION['home_username']=$username;
                          $_SESSION['face65']=$row['minitouxiang']; 
                          $_SESSION['face100']=$row['maxtouxiang']; 
    	             //如果点击记住我，设置cookie，期限到浏览器关闭
                          if(isset($remember)&&$remember==1){
                                       setcookie('username',$row['username'],0,'/');
                                       setcookie('password',$row['password'],0,'/');
                                       //如果选择记住我，下次登陆时这个钩还在；
                                       setcookie('remember',$_POST['remember'],0,'/');
                          }
                          //如果没有，清除上次点击保存时的session
                          if(empty($remember)){
                                       if(!empty($_COOKIE['username'])){
                                                    setcookie('username',$row['username'],time()-100,'/');
                                                    setcookie('password',$_POST['password'],time()-100,'/');
                                                    setcookie('remember',$_POST['remember'],time()-100,'/');
                                       }
                                
                        }
                         $this->success("登陆成功",U('AfterLogin/index'));
    	}
    	else{
    		$this->error("用户名或密码错误",U('Index/index'));
    	}
           
    }
    public function loginout(){
    	//清空当前内存中的session中的数据
    	$_SESSION=array();

    	//删除客户端cookie文件
    	setcookie('PHPSESSID','',time()-3600,'/');

    	//删除服务器上session文件
    	session_destroy();

    	$this->success('退出成功',U('Index/index'));
    }
    public function insert(){
        echo "<pre>";
        print_r($_FILES);
        echo "</pre>";
        import('ORG.Net.UploadFile');
        import('ORG.Util.Image');

        $upload = new UploadFile();
        $upload->savePath = './Public/Uploads/';
        if($upload->upload()){
            $arr=$upload->getUploadFileInfo();
            $path=$arr[0][savepath];
            $src=$path.$arr[0][savename];
            $dst=$path.'thumb_'.$arr[0][savename];

            if(Image::thumb($src,$dst,'',65,40)){
                echo "{$arr[0]['savename']}上传成功!";
            }else{
               echo "上传失败!"; 
            }
        }





    }

    }